package com.hubery.designpattern.service.impl;

import com.hubery.designpattern.design.decorator.dto.UserInfoDTO;
import com.hubery.designpattern.design.decorator.impl.AppFillUserInfoDecorator;
import com.hubery.designpattern.dto.PrizeProvideReqDTO;
import com.hubery.designpattern.service.ActivityService;
import com.hubery.designpattern.design.template.gant.GantPrizeTemplateSupport;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Objects;

/**
 * @author: lxy
 * @date: 2023/2/28 00:23
 * @Description:
 */
@Slf4j
@Component
public class ActivityServiceImpl extends GantPrizeTemplateSupport implements ActivityService {

    @Resource
    private AppFillUserInfoDecorator appFillUserInfoDecorator;

    @Override
    public void providePrize(PrizeProvideReqDTO reqDTO) {
        log.info("开始为用户编号为 【{}】 的用户发放奖品 【{}】", reqDTO.getUserId(), reqDTO.getPrizeTypeEnum());
        //填充用户信息
        UserInfoDTO userInfoDTO = appFillUserInfoDecorator.fillUserInfo(reqDTO.getUserId());
        if (Objects.isNull(userInfoDTO)) {
            return;
        }

        //开始执行发放奖品流程
        getGantPrizeTemplateService(userInfoDTO.getUserTypeEnum()).process(userInfoDTO, reqDTO);
    }
}
